/* GUI CONVERTED from ececmt.p (converter v1.76) Thu Apr 17 20:54:30 2003 */
/* ececmt.p - ECR/ECN MAINTENANCE                                            */
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/* $Revision: 1.18.1.16 $                                                         */
/*V8:ConvertMode=Maintenance                                                 */
/* REVISION: 7.4      LAST MODIFIED: 07/01/93   BY: pma *H013*               */
/* REVISION: 7.4      LAST MODIFIED: 05/13/94   BY: qzl *H370* sr101812      */
/* REVISION: 7.4      LAST MODIFIED: 08/12/94   BY: qzl *H480* sr103110      */
/* REVISION: 7.4      LAST EDIT: 10/27/94       BY: ame *H578*               */
/*                               03/21/95       by: srk *H0C4*               */
/* REVISION: 8.5      LAST EDIT: 11/22/95       BY: tvo *J094*               */
/* REVISION: 7.4      LAST MODIFIED: 12/29/95   BY: qzl *H0J1*               */
/* REVISION: 8.5      LAST MODIFIED: 07/31/96   BY: *G2BB*   Russ Witt       */
/* REVISION: 8.5      LAST MODIFIED: 08/13/96   BY: *H0M8*   Russ Witt       */
/* REVISION: 8.5      LAST MODIFIED: 11/01/96   BY: *H0N6*   Russ Witt       */
/* REVISION: 8.6      LAST MODIFIED: 12/05/96   BY: Joe Gawel       *K00C*   */
/* REVISION: 8.6      LAST MODIFIED: 02/20/97   BY: Joe Gawel       *K05X*   */
/* REVISION: 8.6      LAST MODIFIED: 03/18/97   BY: Verghese Kurien *K07Q*   */
/* REVISION: 8.6      LAST MODIFIED: 03/24/97   BY: Joe Gawel       *K08J*   */
/* REVISION: 8.6      LAST MODIFIED: 04/17/97   BY: Joe Gawel       *K0BT*   */
/* REVISION: 8.6      LAST MODIFIED: 04/28/97   BY: Joe Gawel       *K0CK*   */
/* REVISION: 8.6      LAST MODIFIED: 05/22/97   BY: Joe Gawel       *K0BQ*   */
/* REVISION: 8.6      LAST MODIFIED: 08/13/97   BY: Joe Gawel       *K0H5*   */
/* REVISION: 8.6      LAST MODIFIED: 10/07/97   BY: John Worden     *K0LP*   */
/* REVISION: 8.6      LAST MODIFIED: 01/17/97   BY: *H1J8* Felcy D'Souza     */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane         */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan        */
/* REVISION: 8.6E     LAST MODIFIED: 07/14/98   BY: *J2RJ* Niranjan R.       */
/* REVISION: 8.6E     LAST MODIFIED: 07/16/98   BY: *J2RT* Niranjan R.       */
/* REVISION: 9.1      LAST MODIFIED: 09/27/99   BY: *L0JG* Prashanth Narayan */
/* REVISION: 9.1      LAST MODIFIED: 02/22/00   BY: *L0S0* Mark Christian    */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1      LAST MODIFIED: 05/12/00   BY: *N09X* Antony Babu       */
/* REVISION: 9.1      LAST MODIFIED: 06/15/00   BY: *L0ZD* Vandna Rohira     */
/* REVISION: 9.1      LAST MODIFIED: 08/14/00   BY: *N0KW* Jacolyn Neder     */
/* REVISION: 9.1      LAST MODIFIED: 08/23/00   BY: *N0MZ* BalbeerS Rajput   */
/* REVISION: 9.1      LAST MODIFIED: 01/08/01   BY: *M0YL* Mark Christian    */
/* Old ECO marker removed, but no ECO header exists *F0PN*                   */
/* Revision: 1.18.1.14     BY: Saurabh C.       DATE: 03/14/02  ECO: *N1D6*  */
/* Revision: 1.18.1.15     BY: Kirti Desai       DATE: 01/22/03  ECO: *N24X*  */
/* $Revision: 1.18.1.16 $    BY: Narathip W.       DATE: 04/16/03  ECO: *P0PW*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

{mfdtitle.i "2+ "}
{cxcustom.i "ECECMT.P"}

/* CONTAINS THE DEFINITION OF global_recid, window_recid */
/* AND swindow_recid                                     */
{mf1.i}
define input parameter doctype like ecm_doc_type.

define new shared variable local_type   like ecm_type.
define new shared variable frameb_title as character format "x(40)"
                                        initial "".

define variable doc        as   character.
define variable nbr        like ecm_nbr label "Number".
define variable ecmid      like wo_lot.
define variable dbase      like si_db.
define variable new_ecn    like mfc_logical.
define variable ecm_recid  as   recid.
define variable section    as   integer.
define variable prog_name  like mnd_exec.
define variable prog_type  as   character.
define variable sngl_yn    like mfc_logical.
define variable auto_nbr   like mfc_logical.
define variable i          as   integer.
define variable msgnbr     like msg_nbr.
define variable warnlvl    as   integer.
define variable len        as   integer.
define variable del-yn     like mfc_logical initial no.
define variable l_pcr_nbr  like ecm_nbr no-undo.
define variable l_pcr_nbr1 like ecm_nbr no-undo.
define variable mtitle     like mnt_label.
define variable prog_title as character format "x(40)".


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
{ecform01.i}
 SKIP(.4)  /*GUI*/
with frame a attr-space side-labels width 80 NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

if false
then do:
   {gprun0.i ""ececmt.p""}
   {gprun0.i ""ecmttrl.p""}
end.

mainloop:
repeat with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.


   hide frame b.
   view frame a.

   assign
      nbr       = ""
      ecmid     = ""
      dbase     = ""
      new_ecn   = no
      prog_name = "ececmt.p"
      section   = 0.

   nbrloop:
   do transaction on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


      find first pcc_ctrl no-lock no-error.
      if not available pcc_ctrl
      then do:
         /* PCC DOES NOT EXIST */
         {pxmsg.i &MSGNUM=2136 &ERRORLEVEL=3}
      end.

      global_recid  = ?.
      /*V8+*/
              swindow_recid = ?.   

      prompt-for ecm_nbr
         ecmid when (available pcc_ctrl and pcc_ecooff_date <> ?)
         dbase when (available pcc_ctrl and pcc_ecooff_date <> ?)
         with frame a
      editing:

         /* Allow last number refresh */
         if keyfunction(lastkey) = "RECALL"
            or lastkey = 307
         then
            display
               nbr @ ecm_nbr with frame a.

         {mfnp05.i ecm_mstr ecm_mstr
            "((ecm_rel_date = ?) and (ecm_close_date = ?))"
            ecm_nbr "input ecm_nbr"}

         /* THE FOLLOWING CODE POPULATES THE NUMBER (ecm_nbr), ID (ecmid),   */
         /* DATABASE (dbase), TYPE (ecm_type), DESIGN GROUP (ecm_assign) AND */
         /* DOCUMENT TYPE (ecm_doc_type) FIELDS WHEN THE BROWSE OPTION IS    */
         /* EXERCISED ON THE NUMBER (ecm_nbr) OR THE ID (ecmid) FIELDS       */

         /* THE FOLLOWING CODE WILL BE EXECUTED IN THE CHUI ENVIRONMENT ONLY */
         /*V8+*/

         /* THE FOLLOWING CODE WILL BE EXECUTED IN THE GUI ENVIRONMENT ONLY */
              
         if global_recid <> ?
         then
            recno = global_recid.
         else
         if swindow_recid <> ?
         then
            recno = swindow_recid.
           

         /* THE FOLLOWING CODE WILL BE EXECUTED IN THE CHUI ENVIRONMENT ONLY */
         /*V8+*/

         /* THE FOLLOWING CODE WILL BE EXECUTED IN THE GUI ENVIRONMENT ONLY */
              
         if global_recid  <> ?
         or swindow_recid <> ?
         then do:
           

            for first ecm_mstr
               fields (ecm_approval   ecm_appr_date ecm_assign
                       ecm_close_date ecm_cmmt      ecm_distr
                       ecm_doc_type   ecm_init      ecm_mod_date
                       ecm_name       ecm_nbr       ecm_open_date
                       ecm_rel_date   ecm_replan    ecm_status
                       ecm_sub_date   ecm_title     ecm_type
                       ecm_user1      ecm_user2     ecm_userid)
               where recid(ecm_mstr) = recno
            no-lock:
            end. /* FOR FIRST ecm_mstr */

            global_recid  = ?.
            /*V8+*/
                        swindow_recid = ?.   

         end. /* IF global_recid <> ? */

         if recno <> ?
         then do:
            assign
               ecmid = substring(ecm_nbr,9,8)
               dbase = substring(ecm_nbr,17,8).

            display {ecform12.i} with frame a.
         end. /* IF recno <> ? */

      end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* PROMPT-FOR ecm_nbr */

      global_recid = ?.

      assign ecmid dbase.

      if input ecm_nbr <> ""
      then do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

         if keyfunction (lastkey) = "end-error" then next mainloop.

         nbr = string(input ecm_nbr, "x(8)")
             + string(ecmid, "x(8)")
             + string(dbase, "x(8)").

         /*** Changed convert program, so closed ECR will have "*"
         if can-find (ecm_mstr where ecm_nbr = nbr + "*") then
         nbr = nbr + "*".      **QZL*******/

         find first ecm_mstr exclusive-lock where ecm_nbr = nbr
            no-error no-wait.
         if locked (ecm_mstr)
         then do:
            /*Record Locked*/
            {pxmsg.i &MSGNUM=7422 &ERRORLEVEL=4}
            undo nbrloop, retry.
         end.

         if available ecm_mstr
         and ecm_doc_type <> doctype
         then do:

            if doctype = "PCO"
            then do:
               /* DOCUMENT TYPE MUST BE PCO*/
               {pxmsg.i &MSGNUM=1760 &ERRORLEVEL=3}
            end.
            else do:
               /* DOCUMENT TYPE MUST BE PCR*/
               {pxmsg.i &MSGNUM=1761 &ERRORLEVEL=3}
            end.
            undo nbrloop, retry nbrloop.
         end.

         if not available ecm_mstr
         then do:
            {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}
            create ecm_mstr.
            assign
               new_ecn = yes
               ecm_init = global_userid
               ecm_nbr = nbr.
            if recid(ecm_mstr) = -1 then .

            /*FIND SUBSIDIARY RECORDS*/
            {gprun.i ""ececmta.p""
               "(input recid(ecm_mstr),
                 input yes,
                 input yes,
                 output sngl_yn)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            /*NO SUBSIDIARY RECORDS FOUND*/
            type2loop:
            do on error undo type2loop, retry with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.

               display
                  ecm_type
                  ecm_assign
                  ecm_init.

               prompt-for
                  ecm_type
                  ecm_assign
                  ecm_init
               with frame a
               editing:
                  local_type = input ecm_type.

                  {mfnp05.i pct_mstr pct_type
                     "pct_doc_type = doctype"
                     pct_type "input ecm_type"}

          /* THE FOLLOWING CODE POPULATES THE TYPE (ecm_type), DESIGN GROUP   */
          /* (ecm_assign) AND THE DOCUMENT TYPE (ecm_doc_type) FIELDS WHEN    */
          /* THE BROWSE OPTION IS EXERCISED ON EITHER THE TYPE (ecm_type)     */
          /* OR THE DESIGN GROUP (ecm_assign) FIELDS                          */

          /* THE FOLLOWING CODE WILL BE EXECUTED IN THE CHUI ENVIRONMENT ONLY */
                  /*V8+*/

           /* THE FOLLOWING CODE WILL BE EXECUTED IN THE GUI ENVIRONMENT ONLY */
                       
                  if global_recid <> ?
                  then
                     recno = global_recid.
                  else
                  if swindow_recid <> ?
                  then
                     recno = swindow_recid.
                    

          /* THE FOLLOWING CODE WILL BE EXECUTED IN THE CHUI ENVIRONMENT ONLY */
                  /*V8+*/

           /* THE FOLLOWING CODE WILL BE EXECUTED IN THE GUI ENVIRONMENT ONLY */
                       
                  if global_recid  <> ?
                  or swindow_recid <> ?
                  then do:
                    

                     for first pct_mstr
                        fields (pct_approval pct_distr  pct_doc_type
                                pct_dsgn_grp pct_prefix pct_type)
                        where recid(pct_mstr) = recno
                     no-lock:
                     end. /* FOR FIRST pct_mstr */

                     global_recid  = ?.
             /*V8+*/
                     swindow_recid = ?.   

                  end. /* IF global_recid <> ? */

                  if recno <> ? then
                     display
                        pct_type     @ ecm_type
                        pct_dsgn_grp @ ecm_assign
                        pct_doc_type @ ecm_doc_type
                     with frame a.

               end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* PROMPT-FOR ecm_nbr */

               find pct_mstr
                  where pct_type     = input ecm_type
                  and   pct_dsgn_grp = input ecm_assign
               no-lock no-error.

               if not available pct_mstr
               then do:
                  /* TYPE/GROUP DOES NOT EXIST */
                  {pxmsg.i &MSGNUM=5604 &ERRORLEVEL=3}
                  next-prompt ecm_type with frame a.
                  undo type2loop, retry.
               end.   /* IF NOT AVAILABLE pct_mstr */

               else
               if available pct_mstr
               and pct_doc_type <> doctype
               then do:
                  if doctype = "PCO"
                  then do:
                     /* DOCUMENT TYPE MUST BE PCO*/
                     {pxmsg.i &MSGNUM=1760 &ERRORLEVEL=3}
                  end.
                  else do:
                     /* DOCUMENT TYPE MUST BE PCR*/
                     {pxmsg.i &MSGNUM=1761 &ERRORLEVEL=3}
                  end.
                  next-prompt ecm_type with frame a.
                  undo type2loop, retry type2loop.
               end.

               assign
                  ecm_init
                  ecm_type      = pct_type
                  ecm_assign    = pct_dsgn_grp
                  ecm_open_date = today
                  ecm_distr     = pct_distr
                  ecm_approval  = pct_approval
                  ecm_init      = global_userid
                  ecm_replan    = yes
                  ecm_doc_type  = pct_doc_type.

            end.
         end.
         else do:

            i = 0.
            do:

               if (available pcc_ctrl and pcc_initial_date = ?)
                  or not available pcc_ctrl
               then do:
                  /*REVISION LEVELS NOT INITIALIZED*/
                  {pxmsg.i &MSGNUM=5617 &ERRORLEVEL=2}
                  i = i + 1.
               end.

               if (available pcc_ctrl and pcc_ecooff_date = ?)
                  or not available pcc_ctrl
               then do:
                  /*ECO MAINTENANCE NOT DISABLED*/
                  {pxmsg.i &MSGNUM=5652 &ERRORLEVEL=2}
                  i = i + 1.
               end.
               if i > 0 then pause.
               hide message no-pause.
            end.

            if ecm_rel_date <> ?
            then do:
               /* MODIFICATION NOT ALLOWED, DISTRIBUTED */

               {pxmsg.i
                  &MSGNUM=2157
                  &ERRORLEVEL=4
                  &MSGARG1=getTermLabel(""DISTRIBUTED"",25)}
               undo mainloop, retry.
            end.
            else if ecm_close_date <> ?
            then do:
               /* MODIFICATION NOT ALLOWED, CLOSED */

               {pxmsg.i
                  &MSGNUM=2157
                  &ERRORLEVEL=2
                  &MSGARG1=getTermLabel(""CLOSED"",25)}
               pause.
            end.

            else
            if  ecm_sub_date <> ?
            and ecm_appr_date = ?
            then do:
               /* MODIFICATION NOT ALLOWED, SUBMITTED */

               {pxmsg.i
                  &MSGNUM=2158
                  &ERRORLEVEL=2
                  &MSGARG1=getTermLabel(""SUBMITTED"",25)}
               pause.
            end.

            else if ecm_appr_date <> ?
            then do:
               /* APPROVED. MAY REQUIRED RE-APPROVAL */

               {pxmsg.i
                  &MSGNUM=2158
                  &ERRORLEVEL=2
                  &MSGARG1=getTermLabel(""APPROVED"",25)}

               pause.
            end.

            {pxmsg.i &MSGNUM=10 &ERRORLEVEL=1} /* MODIFYING EXISTING RECORD */

            /*FIND SUBSIDIARY RECORDS*/
            {gprun.i ""ececmta.p""
               "(input recid(ecm_mstr),
                 input no,
                 input yes,
                 output sngl_yn)"}
/*GUI*/ if global-beam-me-up then undo, leave.


         end.
      end. /*if input ecm_nbr <> ""*/
      else
         typeloop:
         do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.


         if not available pcc_ctrl
         or not pcc_auto_nbr
         then do:
            /*BLANK NOT ALLOWED*/
            {pxmsg.i &MSGNUM=40 &ERRORLEVEL=3}
            next-prompt ecm_nbr with frame a.
            undo nbrloop, retry.
         end.

         else do:
            display
               global_userid @ ecm_init.
            prompt-for
               ecm_type
               ecm_assign
               ecm_init
               with frame a
            editing:
               local_type = input ecm_type.

               {mfnp05.i pct_mstr pct_type
                  "pct_doc_type = doctype"
                  pct_type "input ecm_type"}

         /* THE FOLLOWING CODE POPULATES THE TYPE (ecm_type), DESIGN GROUP   */
         /* (ecm_assign) AND THE DOCUMENT TYPE (ecm_doc_type) FIELDS WHEN    */
         /* THE BROWSE OPTION IS EXERCISED ON EITHER THE TYPE (ecm_type)     */
         /* OR THE DESIGN GROUP (ecm_assign) FIELDS                          */

         /* THE FOLLOWING CODE WILL BE EXECUTED IN THE CHUI ENVIRONMENT ONLY */
               /*V8+*/

         /* THE FOLLOWING CODE WILL BE EXECUTED IN THE GUI ENVIRONMENT ONLY */
                    
               if global_recid <> ?
               then
                  recno = global_recid.
               else
               if swindow_recid <> ?
               then
                  recno = swindow_recid.
                 

         /* THE FOLLOWING CODE WILL BE EXECUTED IN THE CHUI ENVIRONMENT ONLY */
               /*V8+*/

         /* THE FOLLOWING CODE WILL BE EXECUTED IN THE GUI ENVIRONMENT ONLY */
                    
               if global_recid  <> ?
               or swindow_recid <> ?
               then do:
                 

                  for first pct_mstr
                     fields (pct_approval pct_distr  pct_doc_type
                             pct_dsgn_grp pct_prefix pct_type)
                     where recid(pct_mstr) = recno
                  no-lock:
                  end. /* FOR FIRST pct_mstr */

                  global_recid  = ?.
          /*V8+*/
                  swindow_recid = ?.   

               end. /* IF global_recid <> ? */

               if recno <> ?
               then
                  display
                     pct_type @ ecm_type
                     pct_dsgn_grp @ ecm_assign
                     pct_doc_type @ ecm_doc_type
                  with frame a.

            end. /* PROMPT-FOR ecm_nbr */

            find pct_mstr
               where pct_type = input ecm_type
               and pct_dsgn_grp = input ecm_assign
            no-lock no-error.
            if not available pct_mstr
            then do:
               /*TYPE/GROUP DOES NOT EXIST*/
               {pxmsg.i &MSGNUM=5604 &ERRORLEVEL=3}
               next-prompt ecm_type with frame a.
               undo typeloop, retry.
            end.
            else
            if available pct_mstr
            and pct_doc_type <> doctype
            then do:
               if doctype = "PCO"
               then do:
                  /* DOCUMENT TYPE MUST BE PCO*/
                  {pxmsg.i &MSGNUM=1760 &ERRORLEVEL=3}
               end.
               else do:
                  /* DOCUMENT TYPE MUST BE PCR*/
                  {pxmsg.i &MSGNUM=1761 &ERRORLEVEL=3}
               end.
               next-prompt ecm_type with frame a.
               undo typeloop, retry typeloop.
            end.

            find first pcc_ctrl exclusive-lock
               where pcc_auto_nbr = true no-error.

            repeat:
               i = 2.
               repeat:

                  if pcc_pco_pre[i] = pct_prefix then leave.
                  i = i + 1.
                  if i > 12 then leave.
               end.

               if (i > 12 or pct_prefix = "" or pct_prefix = " ")
               then
                  i = 1.

               if length(pcc_pco_pre[i])
                  + length(string(pcc_next_pco[i])) > 8
               then
                  pcc_next_pco[i] = 0.

               assign
                  len = length(pcc_pco_pre[i])
                      + length(string(pcc_next_pco[i]))

                  nbr = pcc_pco_pre[i]
                      + fill("0", 8 - len)
                      + string(pcc_next_pco[i])

                  pcc_next_pco[i] = pcc_next_pco[i] + 1.

               if length(pcc_pco_pre[i])
                  + length(string(pcc_next_pco[i])) > 8
               then
                  pcc_next_pco[i] = 0.

               if not can-find(first ecm_mstr where ecm_nbr begins nbr)
               then
                  leave.
            end.
         end.
/*GUI*/ if global-beam-me-up then undo, leave.

         nbr = string(nbr, "x(8)")
             + string(ecmid, "x(8)")
             + string(dbase, "x(8)").

         {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}
         new_ecn = yes.
         create ecm_mstr.

         assign
            ecm_init
            ecm_nbr       = nbr
            ecm_type      = pct_type
            ecm_assign    = pct_dsgn_grp
            ecm_open_date = today
            ecm_distr     = pct_distr
            ecm_approval  = pct_approval
            ecm_replan    = yes
            ecm_doc_type  = pct_doc_type.

         release pcc_ctrl.
      end. /*typeloop*/
   end. /*nbrloop*/
   find first pcc_ctrl no-lock no-error. /* REMOVE LOCK */

   /* ADD/MOD/DELETE */
   /*ecm_mstr IS EXCLUSIVELY LOCKED*/
   detail-loop:
   do transaction on error undo, retry with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.


      if keyfunction (lastkey) = "end-error"
         or lastkey = keycode("F4") or lastkey = 304
      then
         next mainloop.

      find first ecm_mstr exclusive-lock where ecm_nbr = nbr.

      ststatus = stline[2].
      status input ststatus.

      assign
         ecm_recid    = recid(ecm_mstr)
         ecm_userid   = global_userid
         ecm_mod_date = today.

      display
         {ecform12.i}
      with frame a.

      if ecm_close_date = ?
      then
         set
            ecm_title
            text(ecm_cmmt)
            ecm_status
            ecm_name
            ecm_user1
            ecm_user2
            go-on(F5 CTRL-D).
      else
         pause 2 no-message.

      /* DELETE */
      if lastkey = keycode("F5")
      or lastkey = keycode("CTRL-D")
      then do:
         /*FIND SUBSIDIARY RECORDS*/
         {gprun.i ""ececmta.p""
            "(input recid(ecm_mstr),
              input no,
              input yes,
              output sngl_yn)"
         }
/*GUI*/ if global-beam-me-up then undo, leave.

         /* STORING ecm_nbr INTO LOCAL VARIABLE */
         assign
            l_pcr_nbr1 = ecm_nbr + hi_char
            l_pcr_nbr  = ecm_nbr.

         del-yn = no.
         {pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=del-yn}
         if del-yn = no then undo.

         /* CALL TO INTERNAL PROCEDURE TO DELETE PCO */
         run del_pco_pcr(buffer ecm_mstr).

         /* FIND SUBSIDIARY ecm_mstr RECORD FOR PCR */
         for first ecm_mstr
            where ecm_nbr >= l_pcr_nbr
            and   ecm_nbr <= l_pcr_nbr1
            exclusive-lock:
         end. /* FOR FIRST ecm_mstr */

         if available ecm_mstr
         then do:
            /* CALL TO INTERNAL PROCEDURE TO DELETE PCR */
            run del_pco_pcr(buffer ecm_mstr).
         end. /* IF AVAILABLE ecm_mstr */

         clear frame a.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
         next mainloop.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.

   end. /*detail-loop*/

   /*ecm_mstr IS SHARE-LOCKED*/
   workloop:
   repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

      pause 0.
      prog_name = "ececmt.p".

      FORM /*GUI*/ 
         
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
ecm_nbr             colon 12 label "Number"
         ecmid               colon 36
         dbase               colon 58
         ecm_doc_type                 no-label format "x(3)"
         ecm_title           colon 12 skip
       SKIP(.4)  /*GUI*/
with frame b attr-space side-labels width 80
          NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-b-title AS CHARACTER.
 F-b-title = frameb_title.
 RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame b =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame b + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame b =
  FRAME b:HEIGHT-PIXELS - RECT-FRAME:Y in frame b - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME b = FRAME b:WIDTH-CHARS - .5. /*GUI*/


      /* SET EXTERNAL LABELS */
      setFrameLabels(frame b:handle).

      {gprun.i ""ececmtb.p""
         "(input ecm_recid,
           input execname,
           output mtitle,
           input-output section)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      if keyfunction(lastkey) = "end-error"
      then
         undo mainloop, retry.

      if section < 1 or section > 9
      then
         undo workloop, retry.

      if section <> 1
      and section <> 8
      then do transaction:
         find first ecm_mstr where recid(ecm_mstr) = ecm_recid
         exclusive-lock no-error.

         /* WHEN PCR/PCO IS MODIFIED, RESET PCR/PCO SUBMITTED    */
         /* AND APPROVED DATES. ALSO, DELETE ROUTING SLIP MASTER */
         /* AND DETAIL RECORDS WHEN IT IS NOT RE-ROUTED          */

         if available ecm_mstr
         then
            assign
               ecm_sub_date  = ?
               ecm_appr_date = ?.

         for first rsu_mstr
            where rsu_doc_nbr   = ecm_nbr
            and   rsu_doc_type  =  ecm_doc_type
            exclusive-lock:
         end.
         if available rsu_mstr
         then do:
            for each rsud_det
               where rsud_index = rsu_index
               exclusive-lock:
               delete rsud_det.
            end.
            delete rsu_mstr.
         end. /* IF AVAILABLE rsu_mstr */

      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      /*TRAILER SECTION*/
      if section = 8
      or ecm_close_date <> ?
      then do:
         if false
         then
            {gprun.i ""ecmttrl.p""}
/*GUI*/ if global-beam-me-up then undo, leave.


         assign
            prog_name = "ecmttrl.p"
            prog_title = "ecmttrl.p " + getTermLabel("TRAILER_MAINTENANCE",25).
      end.
      else do:
         {gprun.i ""ececmtc.p""
            "(input ecm_recid,
              input section,
              input mtitle,
              output prog_type,
              output prog_name,
              output prog_title)"
            }
/*GUI*/ if global-beam-me-up then undo, leave.

         if keyfunction(lastkey) = "end-error"
            or keyfunction(lastkey) = "endkey"
            or lastkey = keycode("F4")
         then
            undo workloop, retry.
      end.

      hide all no-pause.
      /*GUI: view frame dtitle. */
IF global-tool-bar AND global-tool-bar-handle ne ? THEN
  view global-tool-bar-handle. /*GUI*/

      /*THIS WILL SET THE TITLE FOR THE GUI ENVIRONMENT.*/
      /*DYNAMIC FRAME TITLES...WE DO 'EM.               */
      frameb_title = " " + trim(prog_title) + " ".
           
      F-b-title = frameb_title.
      RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.
      RECT-FRAME-LABEL:WIDTH-PIXELS in frame b =
         FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
         RECT-FRAME-LABEL:SCREEN-VALUE in frame b + " ", RECT-FRAME-LABEL:FONT).
        

      view frame b.
      display
         substring(ecm_nbr,1,8)  @ ecm_nbr
         substring(ecm_nbr,9,8)  @ ecmid
         substring(ecm_nbr,17,8) @ dbase
         ecm_doc_type
         ecm_title
      with frame b.

      if (  lastkey = keycode("GO")
         or lastkey = keycode("F1")
         or keyfunction(lastkey) = "GO"
         or lastkey = keycode("RETURN")) and
         (prog_name begins "ec"
         {&ECECMT-P-TAG1}
         or prog_name begins "pc")
      then do transaction:
/*GUI*/ if global-beam-me-up then undo, leave.


         global_recid = ?.
         msgnbr = 0.
         {gprun.i prog_name "(input ecm_recid,
                              input prog_type,
                              input no,
                              output msgnbr,
                              output warnlvl)"}
/*GUI*/ if global-beam-me-up then undo, leave.

      end.
      else
         leave.
      if not available ecm_mstr
      then do:
         clear frame a.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
         leave.
      end.

      if msgnbr <> 0
      then do:
         {pxmsg.i &MSGNUM=msgnbr &ERRORLEVEL=warnlvl}
         pause.
      end.

      if global_recid <> ?
      then do transaction:
/*GUI*/ if global-beam-me-up then undo, leave.

         release ecm_mstr.
         find ecm_mstr where recid(ecm_mstr) = global_recid no-error.
         clear frame a all no-pause.

         hide all no-pause.
         /*GUI: view frame dtitle. */
IF global-tool-bar AND global-tool-bar-handle ne ? THEN
  view global-tool-bar-handle. /*GUI*/

         view frame a.
         if available ecm_mstr
         then do:
            assign
               ecmid = substring(ecm_nbr,9,8)
               dbase = substring(ecm_nbr,17,8).
            display

               {ecform12.i}
            with frame a.

            global_recid = ?.
            leave workloop.
         end.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      find ecm_mstr where ecm_nbr = nbr no-lock no-error.
      global_recid = ?.

      hide all no-pause.
      /*GUI: view frame dtitle. */
IF global-tool-bar AND global-tool-bar-handle ne ? THEN
  view global-tool-bar-handle. /*GUI*/

      view frame a.
      display
         {ecform12.i}
      with frame a.
      if ecm_close_date <> ? or ecm_sub_date <> ? then leave.
   end. /*workloop*/
end. /*mainloop*/
status input.
prog_name = "".

/* ADDED INTERNAL PROCEDURE FOR DELETING PCR/PCO RECORD */

PROCEDURE del_pco_pcr:

   define parameter buffer emstr for  ecm_mstr.

   /* DELETE ITEM DATA CHANGE RECORDS */
   for each ecd_det
      where ecd_nbr = emstr.ecm_nbr
      exclusive-lock:
      delete ecd_det.
   end. /* FOR EACH ecd_det */

   /* DELETE PRODUCT STRUCTURE CHANGE RECORD */
   for each ecd1_det
      where ecd1_nbr = emstr.ecm_nbr
      exclusive-lock:
      delete ecd1_det.
   end. /* FOR EACH ecd1_det */

   /* DELETE ROUTING CHANGE RECORD */
   for each ecd2_det
      where ecd2_nbr = emstr.ecm_nbr
      exclusive-lock:
      delete ecd2_det.
   end. /* FOR EACH ecd2_det */

   /* DELETE TEXT FILE CHANGE RECORDS */
   for each ecd3_det
      where ecd3_nbr = emstr.ecm_nbr
      exclusive-lock:
      delete ecd3_det.
   end. /* FOR EACH ecd3_det */

   /* ALL CORRESPONDING rsud_det RECORDS SHOULD BE DELETED */
   /* BEFORE DELETING THE rsu_mstr RECORD                  */
   for each rsu_mstr
      where rsu_doc_nbr = emstr.ecm_nbr
      exclusive-lock:

      for each rsud_det exclusive-lock
         where rsud_index = rsu_index:
         delete rsud_det.
      end. /* FOR EACH rsud_det */

      delete rsu_mstr.
   end.  /* FOR EACH rsu_mstr */

   /* DELETE TEST RESULT DATA RECORD */
   for each ecd4_det
      where ecd4_nbr = emstr.ecm_nbr
      exclusive-lock:
      delete ecd4_det.
   end.  /* FOR EACH ecd4_det */

   /* DELETE PCR/PCO RECORD IN ecm_mstr */
   delete emstr.

END PROCEDURE. /* END PROCEDURE del_pco_pcr */
